package com.palm.hubo2o;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import butterknife.ButterKnife;

/**
 * Created by dest1 on 2015/9/8.
 */
public abstract class BaseFragment extends Fragment {
    private String mTitle;

    public BaseFragment() {
        super();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(layoutId(), container, false);
        ButterKnife.bind(this, v);
        onCreateView2(v, savedInstanceState);
        return v;
    }

    protected abstract void onCreateView2(View root, Bundle savedInstanceState);

    /**
     * 在{@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}中调用，view中控件的初始化请在
     * {@link #onViewCreated(View, Bundle)}中进行
     *
     * @return fragment的布局id
     */
    protected abstract int layoutId();


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    public void setTitle(String title) {
        this.mTitle = title;
    }

    public String getTitle() {
        if (TextUtils.isEmpty(mTitle))
            return getClass().getName();
        return mTitle;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        PalmApplication.getRefWatcher(getContext()).watch(this);
    }
}
